FROM nginx:1.16-alpine

ARG X_GID
ARG X_UID
ARG BASE_DOMAIN

RUN set -eux; \
    if [ -z "`getent group ${X_GID}`" ]; then \
        addgroup --system --gid ${X_GID} clonetrooper; \
    fi; \
    adduser --system --disabled-password -S --uid ${X_UID} -G clonetrooper clonetrooper && \
    sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk update \
    && apk add -U tzdata \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && apk add openssh-client git mysql-client \
    && apk del tzdata \
    && rm -rf /var/cache/apk/* \
    && rm -rf /root/.cache \                                                                     
    && rm -rf /tmp/* 


COPY ./conf.d/ /etc/nginx/conf.d/
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY  --from=php-yjstoc:latest --chown=clonetrooper:clonetrooper /data/www/yjstoc/ /data/www/yjstoc/
COPY  --from=php-yjstoc:latest --chown=clonetrooper:clonetrooper /data/www/yjstoc-m-fe/ /data/www/yjstoc-m-fe/ 

RUN envsubst '${BASE_DOMAIN}' < /etc/nginx/conf.d/site.conf.template > /etc/nginx/conf.d/site.conf

WORKDIR /data/www/

EXPOSE 80
